<script type="text/javascript">
	function doSearchCard(value) {
		
	}
	
	//表格查询  
	function reloadCard() {
		var params = card_list.datagrid('options').queryParams; //先取得 datagrid 的查询参数  
		printLog(params);
		card_list.datagrid('reload'); //设置好查询参数 reload 一下就可以了  
		card_list.datagrid('unselectAll');
		card_list.datagrid('uncheckAll');
	}


	function addCard() {
		createFromWindow("新增信息", "card.do?editCard", "card.do?saveCard",
				function(data) {
					reloadCard();
				});
	}
	
	function deleteCard() {
		var rows = card_list.datagrid('getChecked');
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要删除吗?',function(r){
	            if (r){
	            	var ids = "";
	            	for(var i=0; i<rows.length; i++){
	            		ids += rows[i].id+",";
	            	}
	                $.post('card.do?deleteCardItems',{ids:ids},function(result){
	                    if (result.success){
	                    	reloadCard();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
	}

	function editCard() {
		var rows = card_list.datagrid('getChecked');
		printLog(rows);
		if (rows&&rows.length>0) {
			if(rows.length>1) {
				showMsg('请选择一条操作记录.');
				return;
			}
			createFromWindow("编辑信息", "card.do?editCard&cardId=" + rows[0].id,
					"card.do?saveCard", function(data) {
						reloadCard();
					},true);
		} else {
			showMsg('请选择操作记录.');
		}

	}
	
	
	//操作按钮触发
	function operationsLookCard(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = card_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			createFromWindow("查看信息", "card.do?editCard&cardId=" + id,
					null, null,false);
		} else {
			showMsg('请选择查看记录.');
		}
	}
	
	function operationsEditCard(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = card_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			createFromWindow("编辑信息", "card.do?editCard&cardId=" + id,
					"card.do?saveCard", function(data) {
						reloadCard();
					},true);
		} else {
			showMsg('请选择编辑记录.');
		}
	}
	
	function operationsCardAuth(id) {
		printLog(id);
		if (id == undefined) {//点击右键菜单才会触发这个
			printLog(id);
			var rows = card_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			createFromWindowOptions({
				title:"卡信息授权",
				maximizable:false,
				href:'card.do?authCard&cardId='+id,
				callback:function(data) {
					saveSelectRooms();
				},
				enableSaveButton:true
			});
		} else {
			showMsg('请选择操作记录.');
		}
	}
	
	function operationsDeleteCard(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = new_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			$.messager.confirm('询问', '你确认要删除吗?', function(r) {
				if (r) {
					$.post('card.do?deleteCardItems', {
						ids : id
					}, function(result) {
						if (result.success) {
							reloadCard(); 
						}
						showMsg(result.msg);
					}, 'json');
				}
			});
		} else {
			showMsg("请选择操作记录.");
		}
	}
	
	function clearCardSearch() {
		setGridSearchParams('card_list','cardSearchForm',true,reloadCard);
	}
	
	//根据条件查询设备
	function cardSearch() {
		setGridSearchParams('card_list','cardSearchForm',false,reloadCard);
	}
</script>

<#assign operations = "[\{shiro:'hotel:card:refresh',onClick:'operationsLookCard',src:'static/jmax/images/notes/note.png',title:'查看'},
	   					\{shiro:'hotel:card:edit',onClick:'operationsEditCard',src:'static/jmax/images/notes/note_edit.png',title:'编辑'},
	   					\{shiro:'hotel:card:auth',onClick:'operationsCardAuth',src:'static/jmax/images/notes/key.png',title:'卡授权'},
	   					\{shiro:'hotel:card:delete',onClick:'operationsDeleteCard',src:'static/jmax/images/notes/note_delete.png',title:'删除'}
	  				   ]"/>

<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'center',border:false">
		
		<@eu.datagrid id="card_list" toolbar="#cardlist_search" idField="id" operations="${operations!}"
			 url="card.do?loadList" rownumbers="true"
			 item="com.xdtech.hotel.vo.CardItem"/>
		
		<div id="cardlist_search">
			<div style="margin-bottom:5px;padding-left:5px;margin-top: 5px;">
				<form id="cardSearchForm">
					<table>
						<tr>
							<td>卡号类型：</td>
							<td>
								<@eu.comboBox id="cardType" url="cardType.do?loadCardTypeList" name="cardType"/>
							</td>
							<td>卡号：</td>
							<td><input type="text" name="cardNo" style="width: 150px" /></td>
							<td>
								<@eu.linkbutton showName="查询" iconCls="icon-search" onclick="cardSearch()"/>
	 					 		<@eu.linkbutton showName="清空" iconCls="icon-clear" onclick="clearCardSearch()"/>
 					 		</td>
						</tr>
					</table>
				</form>
				
			</div>
			<div id="card_toolbar" style="height: auto">
				<@eu.linkbutton showName="新增" shiro="hotel:card:add" iconCls="icon-add" onclick="addCard()"/>
				<@eu.linkbutton showName="删除" shiro="hotel:card:delete" iconCls="icon-remove" onclick="deleteCard()"/>
				<@eu.linkbutton showName="编辑" shiro="hotel:card:edit" iconCls="icon-edit" onclick="editCard()"/>
				<@eu.linkbutton showName="刷新" shiro="hotel:card:refresh" iconCls="icon-reload" onclick="reloadCard()"/>
				
			</div>
		</div>
	</div>
</div>